package com.jimmy.nonweb.data.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jimmy.nonweb.data.entity.CommitLog;
import com.jimmy.nonweb.data.mapper.CommitLogMapper;
import com.jimmy.nonweb.data.service.CommitLogService;

import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.Validator;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommitLogServiceImpl extends ServiceImpl<CommitLogMapper, CommitLog> implements CommitLogService {

    @Autowired
    private Validator validator;

    @Override
    public List<CommitLog> findByGitInstance(String gitInstance) {
        return baseMapper.findByGitInstance(gitInstance);
    }

    
    // 示例：添加保存方法，并校验
    public void saveCommitLog(CommitLog commitLog) {
        // 手动校验
        Set<ConstraintViolation<CommitLog>> violations = validator.validate(commitLog);
        if (!violations.isEmpty()) {
            throw new ConstraintViolationException(violations); // 或自定义异常
        }
        // 保存到数据库
        this.save(commitLog);
    }
}